//
//  TrainingProgressView.swift
//  DaRings
//
//  Created by 尹琼 on 2022/12/9.
//

import UIKit
import MYModule

open class TrainingProgressView: View {
    
    public var progress: Double? {
        
        didSet {
            
            guard var progress = progress else {
                progressView.isHidden = true
                return
            }
            
//            print(progress)
            
            
            progress = progress <= 0.01 ? 0.01 : progress
            if progress > 1.0 {
                progress = 1
            }
            progressView.isHidden = progress <= 0.01
            
            progressView.snp.remakeConstraints { make in
                make.left.top.bottom.equalToSuperview()
                make.width.equalTo(bgProgressView.snp.width).multipliedBy(progress)
            }
            
        }
        
    }
    
    public var highProgress: Double? {
        
        didSet {
            
            guard var highProgress = highProgress else {
                highProgressView.isHidden = true
                return
                
            }
            
            highProgressView.isHidden = highProgress <= 0.01
            
            highProgress = highProgress <= 0.01 ? 0.01 : highProgress
            if highProgress > 1.0 {
                highProgress = 1
            }
            highProgressView.snp.remakeConstraints { make in
                make.left.top.bottom.equalToSuperview()
                make.width.equalTo(bgProgressView.snp.width).multipliedBy(highProgress)
            }
            
        }
        
    }
    
    
    open override func makeUI() {
        super.makeUI()
        
        addSubview(bgProgressView)
        addSubview(highProgressView)
        addSubview(progressView)
        
        bgProgressView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        highProgressView.snp.makeConstraints { make in
            make.left.top.bottom.equalToSuperview()
            make.width.equalTo(bgProgressView.snp.width).multipliedBy(0.01)
        }
        
        progressView.snp.makeConstraints { make in
            make.left.top.bottom.equalToSuperview()
            make.width.equalTo(bgProgressView.snp.width).multipliedBy(0.01)
        }
        
    }
    
    private lazy var bgProgressView: View = {
        
        let progressView = View()
        progressView.backgroundColor = UIColor.assist_EEEEEE
        progressView.cornerRadius = 4.0
        return progressView
        
    }()
    
    public lazy var progressView: View = {
        let progressView = View()
        progressView.backgroundColor = UIColor.Training.theme
        progressView.cornerRadius = 4.0
        return progressView
    }()
    
    public lazy var highProgressView: View = {
        let progressView = View()
        progressView.backgroundColor = UIColor.Training.theme.withAlphaComponent(0.4)
        progressView.cornerRadius = 4.0
        return progressView
    }()
    
    
    
    
}
